#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 10;
int t, n;
ll a[MAXN];

bool check(ll x, ll y, ll z) {
    if (x<y && y > z) return true;
    if (x > y && y < z) return true;
    return false;
}

bool check2(ll w, ll x, ll y, ll z) {
    return check(w, x, y) && check(w, y, z) && check(w, x, z) && check(x, y, z);
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];

        ll res = n * 2 - 1;
        for (int i = 1; i <= n - 2; i++) {
            ll x = a[i], y = a[i + 1], z = a[i + 2];
            if (check(x, y, z)) res++;
        }

        for (int i = 1; i <= n - 3; i++) {
            ll w = a[i], x = a[i + 1], y = a[i + 2], z = a[i + 3];
            if (check2(w, x, y, z)) res++;
        }

        cout << res << endl;
    }
    return 0;
}